package model;

import java.util.ArrayList;
import java.io.Serializable;

/**
 * This class uses the Table object, and will be used to show only pertinent information on the GUI
 */
public class TableInformation implements Serializable{
	private ArrayList<PlayerInformation> playerInfos;
	private int maxPlayers;
	private int maxBet;
	private int ante;
	private int pot;
	private boolean isOver;
	
	/**
	 * Constructor, set all the attributes of the TableInformation to those given by the method call
	 */
	public TableInformation(int maxPlayers, int maxBet, int ante, int pot, ArrayList<Player> players, String username, boolean isOver){
		this.maxPlayers = maxPlayers;
		this.maxBet = maxBet;
		this.ante = ante;
		this.pot = pot;
		this.isOver = isOver;
		
		playerInfos = new ArrayList<PlayerInformation>();
		
		//make sure the first player is the given one
		for(Player player: players){
			if(player.getName().equals(""+username)){
				this.playerInfos.add(new PlayerInformation(player.getName(), player.getCurrentHand(), player.getRoundStatus(), player.getChips(), player.getLastBet()));
			}
		}
		
		//then add subsequent players that are not the given one
		for(Player player: players){
			if(!player.getName().equals(""+username)){
				this.playerInfos.add(new PlayerInformation(player.getName(), player.getCurrentHand(), player.getRoundStatus(), player.getChips(), player.getLastBet()));
			}
		}
		
		System.out.println(playerInfos.get(0).getUsername());
	}
	
	//Getters and setters:
	
	public ArrayList<PlayerInformation> getPlayers() {
		return playerInfos;
	}

	public void setPlayers(ArrayList<PlayerInformation> players) {
		this.playerInfos = players;
	}

	public int getMaxPlayers() {
		return maxPlayers;
	}

	public void setMaxPlayers(int maxPlayers) {
		this.maxPlayers = maxPlayers;
	}

	public int getMaxBet() {
		return maxBet;
	}

	public void setMaxBet(int maxBet) {
		this.maxBet = maxBet;
	}

	public int getAnte() {
		return ante;
	}

	public void setAnte(int ante) {
		this.ante = ante;
	}

	public int getPot() {
		return pot;
	}

	public void setPot(int pot) {
		this.pot = pot;
	}
	
	public boolean isOver() {
		return isOver;
	}

	public void setOver(boolean isOver) {
		this.isOver = isOver;
	}

	/**
	 * Get the player who is currently in their turn
	 * @return the PlayerInformation of the player whose currently in their turn
	 */
	public PlayerInformation getTurn(){
		//go through all the players of the table to determine whose turn it is
		for(PlayerInformation player: playerInfos){
			if(player.inTurn())
				return player;
		}
		
		//if no player is in turn, return null
		return null;
	}
}
